package com.miyake.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.miyake.client.datamanage.Paper;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class DsPaper {
	@PrimaryKey 
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)  
	protected Key key;
	
	@Persistent
	private String nodeKey;

	@Persistent
	private String name;
	
	@Persistent
	private List<String> authors = new ArrayList<String>();
	
	public String getEncodedKey() {
		return KeyFactory.keyToString(key);
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getNodeKey() {
		return nodeKey;
	}

	public void setNodeKey(String nodeKey) {
		this.nodeKey = nodeKey;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Paper toRemoteObject() {
		Paper paper = new Paper();
		paper.setKey(getEncodedKey());
		paper.setNodeKey(nodeKey);
		paper.setTitle(name);
		paper.setAuthor("Shigeo Hori");
		return paper;
	}
	
	
}
